<template>
	<view>
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="欢迎进入风动社区"></u-loading-page>
		<view class="banner_box" v-if="!loadding">
			<view class="message">
				<message :color="'fff'"></message>
			</view>
			<u-swiper :list="list2" keyName="image" height="240" indicator indicatorMode="line" @click="bannerClick" circular></u-swiper>
		</view>
		<view v-if="!loadding" class="banner_cont">
			<view class="banner_list" @click="data_info(0)">
				<text class="H">{{getIndexData.today}}</text>
				<text class="tits">今日 ></text>
			</view>
			<view class="banner_list" @click="data_info(1)">
				<text class="H">{{getIndexData.month}}</text>
				<text class="tits">本月 ></text>
			</view>
			<view class="banner_list" @click="data_info(2)">
				<text class="H">{{getIndexData.last_month}}</text>
				<text class="tits">上月 ></text>
			</view>
		</view>
		<view class="manage_box" v-if="!loadding">
			<view class="manage_box_outer">
				<view class="operationClass">
					<view class="titles">
						功能
					</view>
					<u-line></u-line>
					<view class="menuList">
						<view v-for="(item, index) in menu" :key="index" class="manage_list" @click="manage(item.path)">
							<image class="img" :src="item.imgUrl" mode="aspectFit"></image>
							<text>{{item.name}}</text>
						</view>
						
						<!-- <view class="manage_list" @click="manage('/pages/version5/index/apply/index')">
							<image class="img" src="http://community-system.fdkj.top/uploads/20240311/cb218417fa4380071ba5aec5de0349f9.png" mode="aspectFit"></image>
							<text>免费申领</text>
						</view> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import message from '@/component/message.vue'
	var util5 = require('@/util/request5.js');
	export default {
		data() {
			return {
				loadding: true,
				getIndexData: {},
				yesterday: null,
				menu: [],
				userinfo: {},
				list2: [],
			}
		},
		components: {
			message
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo');
			this.getCurrentTime()
			this.getIndexDatas()
			this.getBanner()
			this._menu5()
			uni.setTabBarItem({
				index: 1,
				visible: true
			})
		},
		onShow() {
			this.getIndexDatas()
			this._menu5()
		},
		methods: {
			//获取时间
			getCurrentTime() {
				let Time = new Date();
				Time.setTime(Time.getTime() - 24 * 60 * 60 * 1000);
				this.yesterday = Time.getFullYear() + "-" + (Time.getMonth() + 1) + "-" + Time.getDate();
			},
			// 获取栏目
			async _menu5() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Menu/lists',
					data: {
						type: 1
					},
					header: {
						'token': this.userinfo.token
					}
				});
				if (res.code == 1) {
					res.data.map(item => {
						item.imgUrl = util5.API_URL + item.imgUrl
					})
					this.menu = res.data
				}
			},
			// 终端设置
			manage(path) {
				uni.navigateTo({
					url: path
				})
			},
			// 激活详情
			data_info(type) {
				uni.navigateTo({
					url: '/pages/version5/index/collection/index?type=' + type
				})
			},
			//关于我们
			about_us(id, name) {
				uni.navigateTo({
					url: '/pages/version5/mine/aboutus/aboutus?id=' + id + '&name=' + name
				})
			},
			// 获取首页统计数据
			async getIndexDatas() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'v1/getIndexData',
					header: {
						'token': this.userinfo.token
					}
				});
				this.loadding = false
				if (res.code == 1) {
					this.getIndexData = res.data
				}
			},
			// 获取banner图
			async getBanner() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'v1/getBanner',
					header: {
						'token': this.userinfo.token
					}
				});
				if (res.code == 1) {
					this.list2 = res.data
					this.list2.map(item => {
						item.image = util5.API_URL + item.image
					})
				}
			},
			// banner图点击
			bannerClick(index) {
				if (this.list2[index].url && this.list2[index].url != '') {
					window.location.href = this.list2[index].url
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}

	.banner_box {
		display: flex;
		flex-direction: column;
		background-size: 100% 100%;
		position: relative;

		.banner_tit {
			box-sizing: border-box;
			display: flex;

			.banner_tit_flex {
				flex: 1;
				flex-direction: column;
				align-items: center;

				h3 {
					color: #fff;
					font-size: 56rpx;
					margin-bottom: 10rpx;
				}

				text {
					font-size: 24rpx;
					color: #bfe2ff;
				}
			}
		}

		.message {
			position: fixed;
			right: 10rpx;
			top: -24rpx;
			z-index: 999;
		}
	}

	.activity {
		margin-top: 40rpx;
		padding: 0 20rpx;

		image {
			width: 100%;
			height: 120rpx;
		}
	}

	.banner_cont {
		padding: 50rpx 0rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		width: 95%;
		background: url(@/static/sj_bg.jpg)no-repeat center;
		margin: 40rpx auto 10rpx auto;
		border-radius: 5px;
		box-shadow: 0px 0px 20px -12px #342f2f;

		.banner_list {
			display: flex;
			flex-direction: column;
			flex: 1;

			.H {
				font-size: 34rpx !important;
				color: #8d5c25;
				padding-bottom: 20rpx;
				font-weight: bold;
			}

			text {
				font-size: 28rpx;
				color: #9f7935;
				text-align: center;
			}

			.tits {
				font-weight: bold;
			}
		}
	}

	.manage_box {
		display: flex;
		flex-direction: column;
		padding: 0 20rpx 30rpx 20rpx;

		.manage_box_outer {
			.operationClass {
				margin-top: 30rpx;
				background-color: #fff;
				border-radius: 16rpx;
				box-shadow: 0px 0px 20px -12px #342f2f;

				.titles {
					font-weight: bold;
					font-size: 30rpx;
					padding: 20rpx 30rpx;
				}

				.menuList {
					display: flex;
					flex-wrap: wrap;
					padding-top: 20rpx;

					.manage_list {
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 25%;
						margin-bottom: 20rpx;

						.img {
							width: 80rpx;
							height: 80rpx;
						}
					}
				}
			}
		}

		text {
			font-size: 28rpx;
			line-height: 50rpx;
		}

	}

	.check {
		position: absolute;
		left: 50%;
		transform: translate(-50%, -50%);
		bottom: -7%;
		font-size: 0;
		width: 198rpx;
		height: 54rpx;

		image {
			display: flex;
			width: 95px;
			height: 100%;
		}
	}
</style>